Eth_Broker fix and test changes from js to ts #17
Eth_Broker fix and test changes from js to ts #17saksijas wants to merge 15 commits intoethersphere:mainfrom
Conversation
| ); | ||
| // Getting expected ETH for DAI | ||
| uint256 ethMin = sellRewardDai(_minDaiSellValue); | ||
| uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); |
There was a problem hiding this comment.
why does this revert https://github.com/ethersphere/bzzaar-contracts/pull/7/files ?
There was a problem hiding this comment.
a bit more info - i believe the original change was made in order to allow the caller of the function to account for slippage. using the full amount of DAI received by the contract to calculate the minimum amount of ETH that would be received as a result of the transaction would only work in the case that the slippage is 0%. @ralph-pichler @RyRy79261 could you advise please guys? 😁
There was a problem hiding this comment.
I would be really interested to hear Ralph has to say about this, since he approved #7 by Nicca42. Completely tracing this down to the source is probably warranted as this value might have an impact. I can help with that, but that will take a bit more time than just doing a review.
On the most rudimentary level, the function sellRewardDai says that _daiAmount is the amount of dai to be traded for ETH and this is indeed dai_.balanceOf(address(this)) and not _minDaiValue. However, I see that #7 changed the value passed in at this line (which is now reverted), but did not update the comment for the function sellRewardDai.
There was a problem hiding this comment.
Veronica writes that this could not be properly tested because the solidity versions between the router and this contract are different. If you do this change, at the very least I would call for caution and manually test that this works (and share the test artifacts)
There was a problem hiding this comment.
Hi there, sorry it's been a while since I saw this code base so still need to pull it down but if I recall correctly, in trying to eliminate all potential entropy from the contracts when trying to fix the tests, I think this approach is more explicit as it takes the active balance as directly as possible
That being said it's be a while so I can't recall and specifically deliberate requirement for this line change
| // ------------------------------------------------------------------------- | ||
| // Events | ||
| // ------------------------------------------------------------------------- | ||
|
|
There was a problem hiding this comment.
I know it is not part of this changeset, but I notice that you are using Solidity version 0.5.0 which is rather outdated. Is it in the books to update this?
| returns (bool) | ||
| { | ||
| (uint256 daiNeeded, uint256 ethReceived) = _commonMint( | ||
| (uint256 daiNeeded, uint256 ethReceived, uint256 ethSpent) = _commonMint( |
There was a problem hiding this comment.
ethReceived is an unused variable now, better don't assign it
(uint256 daiNeeded, , uint256 ethSpent) =There was a problem hiding this comment.
Not part of this changeset, but I notice that the comments to the internal function _commonMint don't document the last return value (ethSpent).
| returns (bool) | ||
| { | ||
| (uint256 daiNeeded, uint256 ethReceived) = _commonMint( | ||
| (uint256 daiNeeded, uint256 ethReceived, uint256 ethSpent) = _commonMint( |
| ); | ||
| // Getting expected ETH for DAI | ||
| uint256 ethMin = sellRewardDai(_minDaiSellValue); | ||
| uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); |
| "Curve burn failed" | ||
| ); | ||
| // Getting expected ETH for DAI | ||
| uint256 ethMin = sellRewardDai(_minDaiSellValue); |
There was a problem hiding this comment.
By removing this value, the passed in value _minDaiSellValue (line 301) is not anymore used (only to emit it in an event). Given that this value is not used, it is not best practice to emit it in the event, so you could just remove it from the function signature and also don't emit it in the event. I understand there might be reasons for backwards compatibility that you keep the function signature and event as is (and that this particular change is not even wanted because it is reverting #7 )
| ); | ||
| // Getting expected ETH for DAI | ||
| uint256 ethMin = sellRewardDai(_minDaiSellValue); | ||
| uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); |
There was a problem hiding this comment.
I would be really interested to hear Ralph has to say about this, since he approved #7 by Nicca42. Completely tracing this down to the source is probably warranted as this value might have an impact. I can help with that, but that will take a bit more time than just doing a review.
On the most rudimentary level, the function sellRewardDai says that _daiAmount is the amount of dai to be traded for ETH and this is indeed dai_.balanceOf(address(this)) and not _minDaiValue. However, I see that #7 changed the value passed in at this line (which is now reverted), but did not update the comment for the function sellRewardDai.
| ); | ||
| // Getting expected ETH for DAI | ||
| uint256 ethMin = sellRewardDai(_minDaiSellValue); | ||
| uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); |
There was a problem hiding this comment.
Veronica writes that this could not be properly tested because the solidity versions between the router and this contract are different. If you do this change, at the very least I would call for caution and manually test that this works (and share the test artifacts)
| _tokenAmount, | ||
| daiReward, | ||
| ethMin, | ||
| swapOutputs[1], |
There was a problem hiding this comment.
I find this a very strange change and don't understand why you pass 0 here (the array is initialized but never filled)
There was a problem hiding this comment.
The outputs from the uniswap broker return the number required here in swapOutputs[1]
| ); | ||
| // Getting the amount of ETH received | ||
| ethReceived = address(this).balance; | ||
| ethSpent = swapOutputs[0]; |
There was a problem hiding this comment.
You never use this variable. Why burdening yourself with assigning it (also to initialize and assign the array on lines 421 and 423)
There was a problem hiding this comment.
To match the uniswap broker, the issue with testing was that the values for swapOutputs wasn't being returned in the mocks
No description provided.